<template>
  <div class="nav">
    <div class="container">
      <div class="tab-item"><router-link class="name" to="/home">首页</router-link></div>
      <div class="tab-item">
        <router-link class="name" to="/category" target="_blank">包装分类</router-link>
        <div class="dropdown">
          <ul>
            <li class="dropdownBox" v-for="(item, index) in list1" :key="index" @click="toCateDetails(item.id, item.cate_name, 1)">
              <img class="imgbox" :src="item.pic" alt="" />
              <span>{{ item.cate_name }}</span>
            </li>
          </ul>
        </div>
      </div>
      <div class="tab-item">
        <router-link class="name" to="/industryService/service" target="_blank">产业服务</router-link>
        <div class="dropdown">
          <ul>
            <li class="dropdownBox" v-for="(item, index) in list2" :key="index" @click="toCateDetails(item.id, item.cate_name, 0)">
              <img class="imgbox" :src="item.pic" alt="" />
              <span>{{ item.cate_name }}</span>
            </li>
          </ul>
        </div>
      </div>
      <div class="tab-item"><router-link class="name" to="/releaseRequire" target="_blank">发布需求</router-link></div>
      <div class="tab-item"><router-link class="name" to="/commissionOfficial" target="_blank">委托平台</router-link></div>
      <div class="tab-item"><router-link class="name" to="/statyService" target="_blank">官方服务</router-link></div>
      <div class="tab-item"><router-link class="name" to="/demand" target="_blank">需求中心</router-link></div>
      <div class="tab-item"><router-link class="name" to="/settled" target="_blank">入驻企业</router-link></div>
      <div class="tab-item"><router-link class="name" to="/exhibition" target="_blank">展览会议</router-link></div>
    </div>
  </div>
</template>

<script>
import { getProductsCategory } from '@/request/api';

export default {
  name: 'Nav',
  data() {
    return {
      list1: [],
      list2: [],
      res: '成功添加购物车！'
    };
  },
  created() {
    if (!this.list1.length || !this.list2.length) {
      this.getList();
    }
  },
  methods: {
    getList() {
      let data1 = {
        is_entity: 1,
        page: 1,
        limit: 15,
        pid: 0,
        num: 15
      };
      let data2 = {
        is_entity: 0,
        page: 1,
        limit: 15,
        pid: 0,
        num: 15
      };
      getProductsCategory(data1).then(res => {
        this.list1 = res.data.data;
      });
      getProductsCategory(data2).then(res => {
        this.list2 = res.data.data;
      });
    },
    toCateDetails(id, name, type) {
      let path = type == 1 ? '/category/classify/' : '/industryService/service/classify/';
      let routeUrl = this.$router.resolve({
        path: path + id + '?name=' + name,
        query: { t: Date.now() }
      });
      window.open(routeUrl.href, '_blank');
    }
  }
};
</script>

<style lang="scss" scoped>
.nav {
  height: 65px;
  line-height: 65px;
  font-size: 16px;
  color: #fff;
  background: #e38b2e;
}
.nav .container {
  display: flex;
}
.nav .container .tab-item {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}
.nav .container .tab-item .name {
  display: block;
  width: 100%;
  height: 100%;
  text-align: center;
  line-height: 65px;
}
.nav .container .tab-item:hover {
  color: #e38b2e;
  background: #fcd4a0;
}
.router-link-active {
  color: #e38b2e;
  background: #fcd4a0;
}
.nav .container .tab-item::after {
  content: '';
  width: 1px;
  height: 32px;
  background: #fff;
  position: absolute;
  right: 0;
  top: 16px;
  opacity: 0.4;
}
.nav .container .tab-item:last-of-type::after {
  display: none;
}
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}
.tab-item:hover .dropdown {
  display: block;
}
.dropdown {
  display: none;
  width: 1100px;
  background-color: #ffffff;
  padding: 5px 10px;
  position: absolute;
  left: -83px;
  top: 65px;
  z-index: 101;
  .dropdownBox {
    float: left;
    width: 212px;
    height: 90px;
    margin: 2px 2px;
    background-color: #f3f4f7;
    border: 1px #eee solid;
    box-sizing: border-box;
    cursor: pointer;

    .imgbox {
      width: 110px;
      height: 100%;
      float: left;
    }

    span {
      display: flex;
      align-items: center;
      justify-content: center;
      float: right;
      color: #7e7e7f;
      font-size: 14px;
      font-weight: bold;
      width: 100px;
      height: 100%;
      line-height: 1.5;
      padding: 10px;
    }
  }

  .dropdownBox:hover {
    border: 1px solid #f2f2f2;
    box-sizing: border-box;
  }

  .dropdownBox:hover span {
    color: #e38b2e;
  }
}
.nav .container .tab-item:nth-of-type(3) .dropdown {
  left: -216px;
}
</style>
